<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务主题" prop="forwardTheme">
        <el-input
          v-model="queryParams.forwardTheme"
          placeholder="请输入转发任务主题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-if="userPost!='section_member'"
          v-hasPermi="['forward:record:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['forward:record:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['forward:record:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['forward:record:export']"
        >导出</el-button>
      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column label="转发任务主题" align="center" prop="forwardTheme" />
      <el-table-column label="转发任务描述" align="center" prop="forwardContent" />
      <el-table-column label="转发任务创建人姓名" align="center" prop="userName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="userPost!='commander' && userPost !='section_member' && memberUserId!=scope.row.userId && scope.row.forwardStatus != '0'"
            v-hasPermi="['forward:record:transmit']"
          >转发</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlePerform(scope.row)"
            v-if=" memberUserId!=scope.row.userId && ((scope.row.forwardStatus != '0' && userPost!='commander')
            || (scope.row.forwardStatus == '0' && userPost =='section_member' && scope.row.generateTaskStatus=='0'))"
            v-hasPermi="['forward:record:perform']"
          >执行</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="memberUserId==scope.row.userId"
            v-hasPermi="['forward:record:remove']"
          >撤回</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleForwardDetail(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改任务转发记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" :before-close="handleForwardDialogClose" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="任务主题" prop="forwardTheme">
          <el-input v-model="form.forwardTheme" placeholder="请输入转发任务主题" maxlength="30" show-word-limit/>
        </el-form-item>
        <el-form-item label="任务描述" prop="forwardContent">
          <el-input v-model="form.forwardContent" type="textarea" placeholder="请输入内容" maxlength="100" show-word-limit/>
        </el-form-item>
      <el-form-item label="转发对象">
        <el-select v-if="userPost !='section_chief'" v-model="form.deptIds" multiple placeholder="请选择">
          <el-option
            v-for="item in deptDictionary"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptId"
          ></el-option>
        </el-select>
        <!--科长级别转发给科员级别时，不将下属userId拼接到deptIds字段中，因为下属部门就是科长当前部门-->
        <el-select v-if="userPost == 'section_chief'" v-model="form.memberIds" multiple placeholder="请选择">
        <el-option
          v-for="item in memberDictionary"
          :key="item.userId"
          :label="item.userName"
          :value="item.userId"
        ></el-option>
      </el-select>
      </el-form-item>
      <el-form-item label="附件">
        <el-upload
          class="forwardUpload"
          ref="upload"
          :multiple="true"
          accept=".jpg, .png, .gif, .bmp, .jpeg"
          :headers="upload.headers"
          :action="upload.url"
          :file-list="upload.imgs"
          list-type="picture-card"
          :limit="upload.limit"
          :before-upload="beforeImageUpload"
          :on-success="successFile"
          :on-remove="removeFile"
          :on-exceed="exceedFile"
          :on-preview="handlePictureCardPreview"
        >
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>

    <!--下级部门的转发弹框-->
    <el-dialog :title="forwardForm.title" :visible.sync="forwardForm.open" width="800px" :before-close="handleForwardDialogClose" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="转发对象">
          <el-select v-if="userPost !='section_chief'" v-model="form.deptIds" multiple placeholder="请选择">
            <el-option
              v-for="item in deptDictionary"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId"
            ></el-option>
          </el-select>
          <!--科长级别转发给科员级别时，不将下属userId拼接到deptIds字段中，因为下属部门就是科长当前部门-->
          <el-select v-if="userPost == 'section_chief'" v-model="form.memberIds" multiple placeholder="请选择">
            <el-option
              v-for="item in memberDictionary"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转发备注" prop="forwardRemark">
          <el-input v-model="form.forwardRemark" type="textarea" placeholder="请输入备注" maxlength="100" show-word-limit/>
        </el-form-item>
        <el-form-item label="附件">
          <el-upload
            class="forwardUpload"
            ref="upload"
            :multiple="true"
            accept=".jpg, .png, .gif, .bmp, .jpeg"
            :headers="upload.headers"
            :action="upload.url"
            :file-list="upload.imgs"

            list-type="picture-card"
            :limit="upload.limit"
            :before-upload="beforeImageUpload"
            :on-success="successFile"
            :on-remove="removeFile"
            :on-exceed="exceedFile"
            :on-preview="handlePictureCardPreview"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForwardForm">确 定</el-button>
        <el-button @click="cancelForwardForm">取 消</el-button>
      </div>
    </el-dialog>


    <!--任务看板相关页面-->
    <!-- 添加或修改主任务信息对话框 -->
    <el-dialog :title="taskTitle" :visible.sync="taskOpen" width="600px" :before-close="handleDialogClose" append-to-body>
      <el-form ref="taskForm" :model="taskForm" :rules="taskRules" label-width="80px">
        <el-form-item label="任务主题" prop="taskTheme">
          <el-input v-model="taskForm.taskTheme" placeholder="请输入任务主题" maxlength="30" :disabled="isActionDisable" show-word-limit/>
        </el-form-item>
        <el-form-item label="任务类型">
          <el-select v-model="taskForm.taskType" placeholder="请选择任务类型" :disabled="isActionDisable" @change="changeView">
            <el-option
              v-for="dict in memberPublishType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="任务周期" prop="startDate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="taskForm.startDate"
                              type="date"
                              value-format="yyyy-MM-dd" :disabled="isActionDisable"
                              placeholder="选择开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="----" prop="endDate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="taskForm.endDate"
                              type="date"
                              value-format="yyyy-MM-dd" :disabled="isActionDisable"
                              :picker-options="pickerOptions"
                              placeholder="选择结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="任务描述" prop="taskDescribe">
          <el-input v-model="taskForm.taskDescribe" type="textarea" placeholder="请输入任务描述" maxlength="200" :disabled="isActionDisable" show-word-limit/>
        </el-form-item>
        <el-form-item label="任务对象" prop="taskObjectIds" v-if=" userPost == undefined || (userPost == 'director' || (userPost == 'section_chief' && taskTypeFlag == 2))">
          <el-button v-model="taskForm.taskObjectIds" suffix-icon="el-icon-search" placeholder="点击选择"  @click="chooseObject">
            点击选择
          </el-button>
          <span class="selectComplainNumber" v-if="userPost == 'director' && taskTypeFlag !=3 && taskForm.taskObjectAreasNum && taskForm.taskObjectAreasNum !=''">已选择区域的企业数量：{{taskForm.taskObjectAreasNum}}</span>
          <span class="selectComplainNumber" v-if="checkedCompanyIds.length && checkedCompanyIds.length!=0 && taskTypeFlag ==3 && userPost == 'director' ">已选择企业数量：{{checkedCompanyIds.length}}</span>
          <span class="selectComplainNumber" v-if="checkedCompanyIds.length && checkedCompanyIds.length!=0 && taskTypeFlag ==2 && userPost == 'section_chief' ">已选择企业数量：{{checkedCompanyIds.length}}</span>
        </el-form-item>
        <!--特定任务单独写一个按钮-->
        <el-form-item label="任务对象" prop="taskObjectIds" v-if=" ((userPost == 'section_chief'|| userPost == 'section_member') && taskTypeFlag == 3)">
          <el-button v-model="taskForm.taskObjectIds" suffix-icon="el-icon-search" placeholder="点击选择"  @click="chooseSpecialObject">
            点击选择
          </el-button>
          <span class="selectComplainNumber" v-if="createByOwnFlag =='N' &&specialTaskForm.list&&specialTaskForm.list.length!=0 && taskTypeFlag ==3 ">已选择企业数量：{{specialTaskForm.list.length}}</span>
          <span class="selectComplainNumber" v-if="createByOwnFlag!='N' && checkedCompanyIds&&checkedCompanyIds.length!=0 && taskTypeFlag ==3 ">已选择企业数量：{{checkedCompanyIds.length}}</span>

        </el-form-item>

        <!--科长 选择规则模板-->
        <el-form-item label="规则模板" prop="ruleId" v-if="userPost == 'section_chief' && taskTypeFlag == 1 ">
          <el-select v-model="taskForm.ruleId" placeholder="请选择规则模板" >
            <el-option
              v-for="dict in ruleDictionary"
              :key="dict.id"
              :label="dict.ruleTheme"
              :value="dict.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容" prop="templateId" v-if="(userPost == 'section_chief' && (taskTypeFlag == 1 || taskTypeFlag == 2))">
          <el-select v-model="taskForm.templateId" placeholder="请选择内容模板" >
            <el-option
              v-for="dict in templateDictionary"
              :key="dict.id"
              :label="dict.templateTheme"
              :value="dict.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务类型" v-if="userPost == 'section_chief' && (taskTypeFlag ==2 || taskTypeFlag ==3)">
          <el-select v-model="taskForm.checkType" placeholder="请选择任务类型"  >
            <el-option label="人员选择" value="1" />
            <el-option label="科室任务" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="执行人员" prop="taskObjectIds" v-if=" userPost !=undefined && (userPost != 'director' &&taskForm.checkType == 1) || (userPost == 'section_chief' && taskTypeFlag == 1)">
          <el-table  ref = "multiplePeopleTable" :data="peopleDictionary" :show-header="false" @selection-change="handleSelectionPeopleChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="执行人员" align="center" prop="userName"/>
            <el-table-column label="选择企业" align="center" >
              <template slot-scope="scope">
                <el-button v-if="taskTypeFlag != 1 " @click ="assignStation(scope.row)">点击选择</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="showSubmitButton()" @click="submitTaskForm">确 定</el-button>
        <el-button @click="cancelTask">取 消</el-button>
      </div>
    </el-dialog>

    <!--处长 双随机或周期选择检查对象 弹框-->
    <el-dialog :title ="directorForm.title" :visible.sync="directorForm.open" width="500px" append-to-body>
      <el-table v-loading="directorForm.loading" ref = "multipleTable" :data="directorForm.list" :show-header="false" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="区名" align="center" prop="areaName"/>
        <el-table-column label="当前区域场站数" align="center" prop="count">
          <template slot-scope="scope">
            <span>{{scope.row.count}}家</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="showSubmitButton()" @click="submitDirectorForm">确 定</el-button>
        <el-button @click="directorFormCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--处长特定任务 或科长周期任务 任务对象选择 弹框-->
    <el-dialog :title ="companyForm.title" :visible.sync="companyForm.open" class="teding-dialog" width="800px" append-to-body>
      <el-form :model="queryCompanyParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="企业名称" prop="companyName">
          <el-input
            v-model="queryCompanyParams.stationName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            @keyup.enter.native="handleQueryCompany"
          />
        </el-form-item>
        <el-form-item label="所属区域" prop="taskTheme">
          <el-select v-model="queryCompanyParams.areaCode" placeholder="请选择所属区域">
            <el-option
              v-for="dict in areaPublishDictionary"
              :key="dict.areaCode"
              :label="dict.areaName"
              :value="dict.areaCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryCompany">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="companyForm.loading" ref = "multipleCompanyTable" :data="companyForm.list"  @selection-change="handleSelectionChangeForSpecial">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="企业名称" align="center" prop="stationName"/>
        <el-table-column label="地址" align="center" prop="address"/>
        <el-table-column label="所属区域" align="center" prop="belongName"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="showSubmitButton()" @click="submitSpecialForm">确 定</el-button>
        <el-button @click="specialCompanyFormCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--分配员工场站 特定任务或周期任务 任务对象选择 弹框-->
    <el-dialog :title ="staffForm.title" :visible.sync="staffForm.open"  :before-close="handleStaffDialogClose" append-to-body>
      <el-form :model="queryStaffCompanyParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="企业名称" prop="companyName">
          <el-input
            v-model="queryStaffCompanyParams.stationName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            @keyup.enter.native="handleQueryCompany"
          />
        </el-form-item>
        <el-form-item label="所属区域" prop="taskTheme">
          <el-select v-model="queryStaffCompanyParams.areaCode" placeholder="请选择所属区域">
            <el-option
              v-for="dict in areaPublishDictionary"
              :key="dict.areaCode"
              :label="dict.areaName"
              :value="dict.areaCode">
            </el-option>
          </el-select>
        </el-form-item>,
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="searchStaffCompany">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetStaffQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table  ref = "multipleTable" :data="staffForm.deptShowedCompanyList"  @selection-change="handleSelectionStaffChange">
        <el-table-column  :selectable="selectEnable" type="selection" width="55" align="center" />
        <el-table-column label="企业名称" align="center" prop="stationName"/>
        <el-table-column label="地址" align="center" prop="address"/>
        <el-table-column label="所属区域" align="center" prop="belongName"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="showSubmitButton" @click="submitStaffForm">确 定</el-button>
        <el-button @click="staffFormCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--特定任务 任务对象选择 弹框-->
    <el-dialog :title ="specialTaskForm.title" :visible.sync="specialTaskForm.open" class="teding-dialog" width="800px" append-to-body>
      <el-form :model="queryCompanyParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="企业名称" prop="companyName">
          <el-input
            v-model="queryCompanyParams.stationName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuerySpecialCompany"
          />
        </el-form-item>
        <el-form-item label="所属区域" >
          <el-select v-model="queryCompanyParams.areaCode" placeholder="请选择所属区域">
            <el-option
              v-for="dict in areaPublishDictionary"
              :key="dict.areaCode"
              :label="dict.areaName"
              :value="dict.areaCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuerySpecialCompany">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetSpecialQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="specialTaskForm.loading" ref = "multipleCompanyTable" :data="specialTaskForm.list"  @selection-change="handleSelectionChangeForSpecial">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="企业名称" align="center" prop="stationName"/>
        <el-table-column label="地址" align="center" prop="address"/>
        <el-table-column label="所属区域" align="center" prop="belongName"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="showSpecialSubmitButton()" @click="submitSpecialForm">确 定</el-button>
        <el-button @click="specialCompanyFormCancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--end-->

  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord, exportRecord,getChildDeptList,getMemberInfoList,receiveDeptId,addProcessRecord,getForwardDetail } from "@/api/task/record";
import { listInformation, getInformation, delInformation, addInformation, updateInformation, exportInformation,getDirectorAreaList ,userPost,areaList,getCompanyList,getRandomList,getTemplateList,getDeptUserList,getCheckedCompanyListFromDB,getUserId,getValidateCheckResult,getZqCompanyList} from "@/api/task/information";
import { getToken } from "@/utils/auth";


export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 任务转发记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //当前人员的岗位 commonder-指挥层 director -处长 section_chief -科长 section_member -科员
      userPost: "0",
      //当前人员的部门id
      userDeptId:undefined,
      //子部门字典表
      deptDictionary:[],
      //科长级别：下属人员字典表
      memberDictionary:[],
      //预览图片url
      dialogImageUrl:undefined,
      dialogVisible:false,
      upload: {
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/common/upload",
          //  文件个数
          limit: 5,
          imgs:[],
      },
      forwardForm: {
          title: "",
          open: false,
          loading: true,
          list: [],
      },



      //任务看板处的初始化信息所需字段
      // 任务类型字典
      taskPublishType: [],
      //科员用的任务类型字典
      memberPublishType:[],
      //任务状态字典
      taskPublishStatus: [],
      //区域名称字典
      areaPublishDictionary: [],
      //规则名称字典
      ruleDictionary: [],
      //内容模板名称字典
      templateDictionary: [],
      //人员名称字典
      peopleDictionary: [],
      //显示标识 处长 1-显示区域选择 2-显示企业选择
      changeViewFlag: 1,
      //全局任务类型标识 1-双随机 2-周期 3-特定
      taskTypeFlag: 0,
        checkedAreaCodes: [],
        checkedCompanyIds: [],
      //时间选择框限制
      pickerOptions:{
          disabledDate(time) {
              return time.getTime() <= Date.now() - 24 * 60 * 60 * 1000
          }
      },
      //新增任务弹框数据
      taskForm:{},
        // 表单校验
        taskRules: {
            userId: [
                {required: true, message: "任务发布人id不能为空", trigger: "blur"}
            ],
            deptId: [
                {required: true, message: "任务发布人部门id不能为空", trigger: "blur"}
            ],
            postCode: [
                {required: true, message: "任务发布人岗位code不能为空", trigger: "blur"}
            ],
            taskTheme: [{required: true, message: "任务主题不能为空", trigger: "blur"}],
            taskType: [{required: true, message: "任务类型不能为空", trigger: "blur"}],
            startDate: [{required: true, message: "任务开始日期不能为空", trigger: "blur"}],
            endDate: [{ message: "任务结束日期不能为空", trigger: "blur"}],
        },
        taskOpen:false,
        taskTitle:"",
        taskLoading:true,
        // 主任务信息表格数据
        informationList: [],
        //是否disable (科长和科员级别)
        isActionDisable: false,
        memberUserId:0,
        queryCompanyParams: {
            pageNum: 1,
            pageSize: 18,
            stationName: undefined,
            areaCode: undefined,

        },
        queryStaffCompanyParams: {
            stationName: undefined,
            areaCode: undefined,
        },
        directorForm: {
            title: "",
            open: false,
            loading: true,
            list: [],
        },
        companyForm: {
            title: "",
            open: false,
            loading: true,
            list: [],
        },
        randomForm: {
            title: "",
            open: false,
            loading: true,
            list: [],
        },
        staffForm: {
            title: "",
            open: false,
            loading: true,
            //科长分配员工展示的list 查询时展示
            deptShowedCompanyList: [],
            //分配时选中的list
            deptCheckedList: [],
            //科长选中的list
            deptAllCompanyList: [],
            //查询时用于塞值的list
            deptSaveValueList: [],
            //点击选择时，当前的userId
            staffUserId: undefined,
            //当前用户所对应的被分配的企业及userId 实体类
            userStation: {},
            //当前用户所对应的勾选的list
        },
        specialTaskForm:{
            title:"",
            open:false,
            loading:true,
            list:[],
        },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        userName: undefined,
        deptId: undefined,
        forwardDeptIds: undefined,
        forwardTheme: undefined,
        forwardContent: undefined,
        withdrawStatus: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        forwardTheme: [
          { required: true, message: "转发任务主题不能为空", trigger: "blur" }
        ],
        forwardContent: [
          { required: true, message: "转发任务描述不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getUserPost();
    this.getDeptId();
    this.getList();
    this.getFromTaskBoardInformationInit();
  },
  methods: {
    /** 查询当前人员的岗位*/
    getUserPost() {
        userPost().then(response => {
            this.userPost = response.data;
            console.log(this.userPost);
            if(this.userPost == 'section_chief'){
                this.getMemberList();
            }else{
                this.getChildDept();
            }
        });
    },
    //获取当前人员的deptId，用于拼接在主表中的字段，便于查询
    getDeptId(){
        receiveDeptId().then(response => {
            this.userDeptId = response.data;
        });
    },
    /*科长级别获取当前部门下的下属用户ids*/
    getMemberList(){
      getMemberInfoList().then(response => {
            this.memberDictionary = response.data;
          console.log(this.memberDictionary)
      });
    },
    /*获取当前用户的子部门（当为科长角色时，无子部门，则查询当前部门下的科员角色）*/
    getChildDept() {
        getChildDeptList().then(response => {
            this.deptDictionary = response.data;
            console.log(this.deptDictionary)
        });
    },
    /** 查询任务转发记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.upload.imgs=[];
      this.$refs.upload.clearFiles();
    },
    // 表单重置
    reset() {
      this.form = {
        forwardId: undefined,
        userId: undefined,
        userName: undefined,
        deptId: undefined,
        forwardDeptIds: undefined,
        forwardTheme: undefined,
        forwardContent: undefined,
        withdrawStatus: "0",
        delFlag: undefined,
        createTime: undefined,
        updateTime: undefined,
        deptIds:[],
        memberIds:[],
        forwardRemark:undefined,
        imageList:[],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.forwardId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务转发记录";
    },
    /** 转发按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form.forwardId = row.forwardId;
      this.form.forwardDeptIds = row.forwardDeptIds;
      this.forwardForm.open = true;
      this.forwardForm.title = "任务转发";
    },
    /*提交前校验*/
    validateBeforeSubmit(){
        let form = this.form;
        if(!form.forwardTheme  ){
            this.msgError("请输入转发任务主题！");
            return false;
        }
        if(!form.forwardContent ){
            this.msgError("请输入转发任务内容！");
            return false;
        }
        if(this.userPost != 'section_chief'){
            if(!form.deptIds || form.deptIds== undefined ||form.deptIds.length == 0){
                this.msgError("请选择下属部门进行转发!");
                return false;
            }
        }else if(this.userPost == 'section_chief'){
            if(!form.memberIds || form.memberIds == undefined || form.memberIds.length == 0){
               this.msgError("请选择下属人员进行转发！");
               return false;
            }
        }
        //校验完后，对部门id进行拼接
        if(this.form.forwardDeptIds == null || this.form.forwardDeptIds == '' || this.form.forwardDeptIds == undefined){
            /*科长转发给科员时，deptIds中没有值，在此进行一次判断*/
            if(this.form.deptIds && this.form.deptIds !=""){
                this.form.forwardDeptIds = this.userDeptId +','+this.form.deptIds.join(",");
            }else{
                /*本部门下分配给下属部门，所以就是用当前部门id分配*/
                this.form.forwardDeptIds = this.userDeptId +','+this.userDeptId;
            }
        }else{
            /*科长转发给科员时，deptIds中没有值，在此进行一次判断*/
            if(this.form.deptIds && this.form.deptIds !="" ){
                this.form.forwardDeptIds = this.form.forwardDeptIds +','+this.userDeptId+','+this.form.deptIds.join(",");
            }else{
                /*本部门下分配给下属部门，所以就是用当前部门id分配*/
                this.form.forwardDeptIds = this.form.forwardDeptIds +','+this.userDeptId+','+this.userDeptId;
            }
        }
        this.form.imageList = [];
        this.upload.imgs.forEach(item => {
            this.form.imageList.push(item.url)
        })
        console.log(this.form.imageList)
        return true;
    },
    /** 提交按钮 */
    submitForm: function() {
      if(!this.validateBeforeSubmit()){
          return;
      }
        this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.forwardId != undefined) {
            updateRecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addRecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
            this.$refs.upload.clearFiles();
        }
      });
    },
    validateBeforeForwardSubmit(){
        let form = this.form;
        if(this.userPost != 'section_chief'){
            if(!form.deptIds || form.deptIds== undefined ||form.deptIds.length == 0){
                this.msgError("请选择下属部门进行转发!");
                return false;
            }
        }else if(this.userPost == 'section_chief'){
            if(!form.memberIds || form.memberIds == undefined || form.memberIds.length == 0){
                this.msgError("请选择下属人员进行转发！");
                return false;
            }
        }
        if(!form.forwardRemark ){
            this.msgError("请输入转发任务备注！");
            return false;
        }
        //校验完后，对部门id进行拼接
        if(this.form.forwardDeptIds == null || this.form.forwardDeptIds == '' || this.form.forwardDeptIds == undefined){
            if(this.form.deptIds && this.form.deptIds !="" ){
                this.form.forwardDeptIds = this.userDeptId +','+this.form.deptIds.join(",");
            }else{
                /*本部门下分配给下属部门，所以就是用当前部门id分配*/
                this.form.forwardDeptIds = this.userDeptId +','+this.userDeptId;
            }
        }else{
            /*科长转发给科员时，deptIds中没有值，在此进行一次判断*/
            if(this.form.deptIds && this.form.deptIds !="" ){
                this.form.forwardDeptIds = this.form.forwardDeptIds +','+this.userDeptId+','+this.form.deptIds.join(",");
            }else{
                /*本部门下分配给下属部门，所以就是用当前部门id分配*/
                this.form.forwardDeptIds = this.form.forwardDeptIds +','+this.userDeptId+','+this.userDeptId;
            }
        }
        this.form.imageList = [];
        this.upload.imgs.forEach(item => {
            this.form.imageList.push(item.url)
        })
        console.log(this.form.imageList)
        return true;
    },
    submitForwardForm: function(){
        if(!this.validateBeforeForwardSubmit()){
            return;
        }
        addProcessRecord(this.form).then(response => {
            if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.forwardForm.open = false;
                this.getList();
            }
        });
        this.$refs.upload.clearFiles();
    },
    cancelForwardForm: function(){
        this.forwardForm.open = false;
        this.reset();
        this.upload.imgs=[];
        this.$refs.upload.clearFiles();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const forwardIds = row.forwardId;
      this.$confirm('是否确认撤回该任务转发记录的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecord(forwardIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("撤回成功");
        }).catch(function() {});
    },
    /*详情*/
    handleForwardDetail(row){
      const forwardId = row.forwardId;
       this.reset();
      //   const res = getForwardDetail(forwardId)
      //   console.log(res)
      this.$router.push({
          path:"/taskk/recordDetail",
          query:{
              forwardId:forwardId
          }
      })
      // console.log(this.$router);
      // getWaybill(waybillId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "运单详情";
      // });
    },
    handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
    },
    beforeImageUpload(file){
        const isLt2M = file.size / 1024 / 1024 < 10
        if (!isLt2M) {
            this.$message.error('上传图片大小不能超过 10MB!')
            return false
        }
    },
    exceedFile(files, fileList) {
        let msg = `最多只能上传${this.upload.limit}个图片`;
        this.$message.warning(msg)
    },
      successFile(response, file){
        this.upload.imgs.push({name:response.fileName,url:response.fileName});
      },
      removeFile(file,fileList){
          this.upload.imgs = [];
          fileList.forEach(detail => {
              this.upload.imgs.push({name:detail.url,url:detail.url});
          })
          console.log(this.upload.imgs);
      },
    //点击关闭按钮触发的事件
    handleForwardDialogClose(){
      this.$refs.upload.clearFiles();
      this.open = false;
      this.forwardForm.open = false;
      this.upload.imgs=[];
      this.reset();
    },

    //初始化看板页面信息
    getFromTaskBoardInformationInit(){
        this.getDicts("task_publish_type").then(response => {
            this.taskPublishType = response.data;
        });

        this.getDicts("task_publish_status").then(response => {
            this.taskPublishStatus = response.data;
        });
        this.getAreaList();
        this.getRuleList();
        this.getTaskTemplateList();
        this.getPeopleList();
        this.receiveUserId();
    },
      /** 查询区域列表*/
      getAreaList() {
          areaList().then(response => {
              this.areaPublishDictionary = response.data;
          });
      },
      //查询规则
      getRuleList() {
          getRandomList().then(response => {
              this.ruleDictionary = response.data;
          });
      },
      //查询内容
      getTaskTemplateList() {
          getTemplateList().then(response => {
              this.templateDictionary = response.data;
          });
      },
      //查询人员姓名
      getPeopleList() {
          getDeptUserList().then(response => {
              this.peopleDictionary = response.data;
          });
      },
      //科员需要查询自己的userId
      receiveUserId(){
          getUserId().then(response => {
              this.memberUserId = response.data;
          });
      },
      //任务弹框重置方法
      resetTask() {
          this.taskForm = {
              id: undefined,
              taskType: undefined,
              taskTheme: undefined,
              startDate: undefined,
              endDate: undefined,
              taskDescribe: undefined,
              taskObjectAreas: undefined,
              taskObjectIds: undefined,
              taskStatus: "1",
              completionTime: undefined,
              userId: undefined,
              deptId: undefined,
              postCode: undefined,
              delFlag: undefined,
              createTime: undefined,
              updateTime: undefined,
              updateId: undefined,
              remark: undefined,
              taskObjectAreasNum: undefined,
              ruleId: undefined,
              peopleId: [],
              templateId: undefined,
              //展示科室任务或人员选择标识 1-科室任务 2-人员选择
              checkType: undefined,
              deptAllCompanyList:[],
              checkedCompanyIds:[],
              forwardId:undefined,
          };
      },
      resetStaffForm(){
          this.staffForm= {
              title: "",
              open: false,
              loading: true,
              //科长分配员工展示的list 查询时展示
              deptShowedCompanyList: [],
              //分配时选中的list
              deptCheckedList: [],
              //科长选中的list
              deptAllCompanyList: [],
              //查询时用于塞值的list
              deptSaveValueList: [],
              //点击选择时，当前的userId
              staffUserId: undefined,
              //当前用户所对应的被分配的企业及userId 实体类
              userStation: {},
              //当前用户所对应的勾选的list
          };
      },
      resetQueryCompanyParam() {
          this.queryCompanyParams = {
              pageNum: 1,
              pageSize: 18,
              stationName: undefined,
              areaCode: undefined,
          };
      },
      resetStaffQueryCompanyParam() {
          this.queryStaffCompanyParams = {
              stationName: undefined,
              areaCode: undefined,
          };
      },
      /** 搜索公司按钮操作 */
      handleQueryCompany() {
          this.queryParams.pageNum = 1;
          this.companyForm.loading = true;
          getCompanyList(this.queryCompanyParams).then(response => {
              this.companyForm.list = response.data;
              this.companyForm.loading = false;
          });
      },
      /** 特定任务搜索公司按钮操作 */
      handleQuerySpecialCompany() {
          this.specialTaskForm.loading = true;
          if(this.createByOwnFlag != "N"){
              getCompanyList(this.queryCompanyParams).then(response => {
                  this.specialTaskForm.list = response.data;
                  this.specialTaskForm.loading = false;
              });
              //非自己创建时，和初始化时一样，需要筛选
          }else if(this.createByOwnFlag == "N"){
              getCompanyList(this.queryCompanyParams).then(response => {
                  this.specialTaskForm.list = response.data;
                  this.specialTaskForm.list = this.specialTaskForm.list.filter(item=>this.checkedCompanyIds.indexOf(item.stationId) >=0);

                  this.specialTaskForm.loading = false;
              });
          }

      },
      //分配企业时的页面查询方法
      searchStaffCompany() {
          this.staffForm.deptSaveValueList=[];
          this.staffForm.deptAllCompanyList.filter(item => {

              if (this.queryStaffCompanyParams.stationName != null && this.queryStaffCompanyParams.stationName != undefined && this.queryStaffCompanyParams.stationName != ""
                  && this.queryStaffCompanyParams.areaCode != null && this.queryStaffCompanyParams.areaCode != undefined && this.queryStaffCompanyParams.areaCode != "") {
                  if (item.stationName.includes(this.queryStaffCompanyParams.stationName) && item.areaCode.includes(this.queryStaffCompanyParams.areaCode)) {
                      this.staffForm.deptSaveValueList.push(item);
                  }
              } else if (this.queryStaffCompanyParams.stationName != null && this.queryStaffCompanyParams.stationName != undefined && this.queryStaffCompanyParams.stationName != "") {
                  if (item.stationName.includes(this.queryStaffCompanyParams.stationName)) {
                      this.staffForm.deptSaveValueList.push(item);
                  }
              } else if (this.queryStaffCompanyParams.areaCode != null && this.queryStaffCompanyParams.areaCode != undefined && this.queryStaffCompanyParams.areaCode != "") {
                  if (item.areaCode.includes(this.queryStaffCompanyParams.areaCode)) {
                      this.staffForm.deptSaveValueList.push(item);
                  }
              }else{
                  this.staffForm.deptSaveValueList.push(item);
              }
          })
          this.staffForm.deptShowedCompanyList = this.staffForm.deptSaveValueList;
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.resetQueryCompanyParam();
          this.handleQueryCompany();
      },
      //特定任务重置按钮
      resetSpecialQuery(){
          this.resetQueryCompanyParam();
          this.handleQuerySpecialCompany();
      },
      /** 重置按钮操作 */
      resetStaffQuery() {
          this.resetStaffQueryCompanyParam();
          this.searchStaffCompany();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
          this.ids = selection.map(item => item.areaCode)
          this.areaNums = selection.map(item => item.count)
          this.single = selection.length != 1
          this.multiple = !selection.length
      },
      //周期任务 多选框选中数据
      handleSelectionChangeForSpecial(selection) {
          this.ids = selection.map(item => item.stationId)
          if(this.userPost != 'director'){
              this.staffForm.deptAllCompanyList = selection.map(item => item)
          }
          this.single = selection.length != 1
          this.multiple = !selection.length
      },
      //双随机任务 规则选中数据

      handleSelectionPeopleChange(selection) {
          this.peopleIds = selection.map(item => item.userId)
          this.single = selection.length != 1
          this.multiple = !selection.length
      },
      //科长给员工分配企业时的多选
      handleSelectionStaffChange(selection) {
          //需要暂存一下，然后在确认时，才去操作

          this.selectionSave = selection;
          // this.staffForm.deptCheckedList = selection.map(item => {
          //     if(item.userId != null && item.userId !=undefined && item.userId !="" && item.userId == this.staffForm.staffUserId){
          //         item.userId = "";
          //     }
          //     return item;
          // })
      },
      //因为给员工分配企业的多选触发事件只是存值，需要在确定时，进行处理
      handleChiefSubmit(){
          this.staffForm.deptCheckedList = this.selectionSave.map(item => {
              if(item.userId != null && item.userId !=undefined && item.userId !="" && item.userId == this.staffForm.staffUserId){
                  item.userId = "";
              }
              return item;
          })
      },
      selectEnable(row,index) {
          if (row.userId != "" && row.userId != null && row.userId != undefined && this.staffForm.staffUserId != row.userId ) {
              return false;//当勾选用户id不相等时，禁用 (如果userId没有值，即当前还未勾选时，不需要禁用)
          } else {
              return true;
          }
      },
      //筛选任务类型
      filterPublishType(){
          this.memberPublishType = this.taskPublishType;
          if(this.userPost == "section_member"){
              this.memberPublishType = this.taskPublishType.filter(item=>item.dictLabel =="特定任务");
          }
      },
      /** 任务弹框新增操作 */
      handlePerform(row) {
          this.resetTask();
          this.resetStaffForm();
          this.taskForm.forwardId = row.forwardId;
          this.taskTypeFlag = 0;
          this.filterPublishType();
          this.checkedAreaCodes = [];
          this.checkedCompanyIds = [];
          this.changeDisableStatus("add");
          this.taskOpen = true;
          this.taskTitle = "发布任务";
          this.createByOwnFlag = undefined;
          this.getSpecialCompanyList();
      },
      changeDisableStatus(str) {
          if (this.userPost == "director") {
              this.isActionDisable = false;
          } else if (this.userPost == "section_chief") {
              if (str == "add") {
                  this.isActionDisable = false;
              } else if (str == "update") {
                  this.isActionDisable = true;
              }
          }
      },
      //处长查看科长的任务时，去除确定按钮
      showSubmitButton(){
          if(this.taskForm.postCode !=this.userPost && this.userPost == "director" && this.taskForm.postCode !=null && this.taskForm.postCode != undefined){
              return false;
          }else if(this.userPost == "director" && this.taskForm.taskStatus != '1'){
              return false;
          }else{
              return true;
          }
      },
      handleDialogClose() {
          if (this.$refs != undefined && this.$refs.multiplePeopleTable != undefined) {
              this.$refs.multiplePeopleTable.clearSelection();
          }
          this.taskOpen = false;
          this.resetTask();

      },
      changeView() {
          if ((this.taskForm.taskType == 3 && this.userPost == "director") || (this.userPost == "section_chief" && this.taskForm.taskType == 2)) {
              this.changeViewFlag = 2;
          } else if ((this.taskForm.taskType == 1 || this.taskForm.taskType == 2) && this.userPost == "director") {
              this.changeViewFlag = 1;
          }
          this.taskTypeFlag = this.taskForm.taskType;
          this.ids = [];
          this.checkedCompanyIds = [];
      },
      submitDirectorForm() {
          this.directorForm.open = false;
          this.checkedAreaCodes = this.ids;
          this.joinAreaCodeStr = this.checkedAreaCodes.join(",");
          this.taskForm.taskObjectAreas = this.joinAreaCodeStr;
          this.taskForm.taskObjectAreasNum = 0;
          this.areaNums.forEach(num => {
              this.taskForm.taskObjectAreasNum += num;
          });
          //特定任务的companyId需要清空
          if (this.userPost == "director") {
              this.taskForm.taskObjectIds = "";
          }
      },
      directorFormCancel() {
          this.directorForm.open = false;
      },
      submitSpecialForm() {
          this.companyForm.open = false;
          this.specialTaskForm.open = false;
          this.checkedCompanyIds = this.ids;
          this.joinCompanyIdStr = this.checkedCompanyIds.join(",");
          this.taskForm.taskObjectIds = this.joinCompanyIdStr;
          //点击确定时，对应双随机，周期任务的区域code，需要清空
          if (this.userPost == "director") {
              this.taskForm.taskObjectAreas = "";
              this.taskForm.taskObjectAreasNum = undefined;
          }
      },
      specialCompanyFormCancel() {
          this.companyForm.open = false;
          this.specialTaskForm.open = false;
      },
      handleStaffDialogClose(){
          //this.submitStaffForm();
          /*            if (this.$refs != undefined && this.$refs.multiplePeopleTable != undefined) {
                          this.$refs.multipleTable.clearSelection();   multipleTable
                      }*/
          if (this.$refs != undefined && this.$refs.multiplePeopleTable != undefined) {
              this.$refs.multipleTable.clearSelection();
          }
          if(this.staffForm.deptCheckedList.length !=0){
              this.staffForm.deptCheckedList.forEach(checked=>{
                  this.staffForm.deptAllCompanyList.forEach(detail=>{
                      if(checked.stationId == detail.stationId){
                          detail.userId = checked.userId;
                      }
                  })
              })
          }
          this.staffForm.deptShowedCompanyList =this.staffForm.deptAllCompanyList;
          this.staffForm.open = false;
      },
      submitStaffForm() {
          this.handleChiefSubmit();
          this.staffForm.open = false;
          this.ids = [];
          this.staffForm.deptCheckedList.forEach(detail => {
              this.ids.push(detail.stationId);
          })
          this.staffForm.deptAllCompanyList.forEach(detail => {
              if(this.ids.indexOf(detail.stationId) == -1 && detail.userId == this.staffForm.staffUserId){
                  detail.userId = "";
              }
          })
          this.staffForm.deptCheckedList.forEach(item => {
              this.staffForm.deptAllCompanyList.forEach(detail => {
                  if (item.stationId == detail.stationId && (detail.userId == null || detail.userId == undefined || detail.userId =="")) {
                      detail.userId = this.staffForm.staffUserId;
                  }
              })
          })
          this.staffForm.deptShowedCompanyList = this.staffForm.deptAllCompanyList;

      },
      staffFormCancel(){
          if (this.$refs != undefined && this.$refs.multiplePeopleTable != undefined) {
              this.$refs.multipleTable.clearSelection();
          }
          if(this.staffForm.deptCheckedList.length !=0){
              this.staffForm.deptCheckedList.forEach(checked=>{
                  this.staffForm.deptAllCompanyList.forEach(detail=>{
                      if(checked.stationId == detail.stationId){
                          detail.userId = checked.userId;
                      }
                  })
              })
          }
          this.staffForm.deptShowedCompanyList =this.staffForm.deptAllCompanyList;
          this.staffForm.open = false;
      },
      //特定任务 科长看处长任务时，去除确定按钮和取消按钮
      showSpecialSubmitButton(){
          if(this.createByOwnFlag == "N" && (this.userPost == "section_chief" || this.userPost == "section_member")){
              return false;
          }else{
              return true;
          }
      },
      /*选择对象*/
      async chooseObject() {
          if (this.validateBeforeClick()) {
              if (this.changeViewFlag == 1) {
                  await getDirectorAreaList().then(response => {
                      this.directorForm.list = response.data;
                      this.directorForm.open = true;
                      this.directorForm.title = "选择检查对象";
                      this.directorForm.loading = false;
                  });
                  if (this.checkedAreaCodes.length != 0) {
                      this.directorForm.list.forEach(area => {
                          if (this.checkedAreaCodes.indexOf(area.areaCode) >= 0) {
                              this.$refs.multipleTable.toggleRowSelection(area, true);
                          }
                      })
                  }
              } else if (this.changeViewFlag == 2) {
                  this.resetQueryCompanyParam();
                  await getCompanyList(this.queryCompanyParams).then(response => {
                      this.companyForm.list = response.data;
                      this.companyForm.open = true;
                      this.companyForm.title = "选择检查对象";
                      this.companyForm.loading = false;
                  });
                  if (this.checkedCompanyIds.length != 0) {
                      this.companyForm.list.forEach(company => {
                          //因为split出来的数组是字符类型
                          if (this.checkedCompanyIds.indexOf(company.stationId) >= 0 || this.checkedCompanyIds.indexOf(company.stationId.toString()) >= 0) {
                              this.$refs.multipleCompanyTable.toggleRowSelection(company, true);
                          }
                      })
                  }
                  //当点击人员的选择分配场站时，去数据库查询详情表，看对应的userId和stationId的对象list，只需要查一次，因为下面的勾选是根据userId来的
                  if(this.staffForm.deptCheckedList.length == 0 && this.userPost !='director'){
                      this.selectcheckedCompanyFromDB();
                  }
              }
          }
      },
      validateBeforeClick() {
          if (this.taskForm.taskType == null || this.taskForm.taskType == undefined) {
              this.msgError("选择对象前，请先确定任务类型！");
              return false;
          } else {
              return true;
          }
      },
      /*任务弹框的提交前校验*/
      //提交前校验
      validateBeforeTaskSubmit(){
          if(this.taskForm.startDate>this.taskForm.endDate){
              this.msgError("开始时间不能超过结束时间，请重新选择！");
              return false;
          }
          if(this.taskForm.formStatusCount !="0" && this.taskForm.formStatusCount!=null && this.taskForm.formStatusCount!=undefined && this.taskForm.postCode !=null && this.taskForm.postCode != undefined){
              this.msgError("已经分配过的任务不能进行更改 ！");
              return false;
          }
          if(this.userPost == "director"){
              if(!this.taskForm.taskType && this.taskForm.taskType != 0){
                  this.msgError("请选择任务类型！");
                  return false;
              }
              if((this.taskTypeFlag == 1 || this.taskTypeFlag == 2) && (!this.taskForm.taskObjectAreas || this.taskForm.taskObjectAreas =='')){
                  this.msgError("请至少选择一个任务对象！");
                  return false;
              }
              if(this.taskTypeFlag == 3 && (!this.taskForm.taskObjectIds || this.taskForm.taskObjectIds=='')){
                  this.msgError("请至少选择一个任务对象！");
                  return false;
              }
          }
          if(this.userPost == "section_chief"){
              if(!this.taskForm.taskType && this.taskForm.taskType != 0){
                  this.msgError("请选择任务类型！");
                  return false;
              }
              if(this.taskTypeFlag == 1 ){
                  if(!this.taskForm.ruleId || this.taskForm.ruleId == ''){
                      this.msgError("请选择随机规则!");
                      return false;
                  }
                  if(!this.taskForm.templateId || this.taskForm.templateId ==''){
                      this.msgError("请选择内容模板！");
                      return false;
                  }
                  if(!this.peopleIds || this.peopleIds == null || this.peopleIds.length == 0){
                      this.msgError("请选择执行人员!");
                      return false;
                  }
              }
              if(this.taskTypeFlag == 2){
                  if(!this.taskForm.templateId || this.taskForm.templateId ==''){
                      this.msgError("请选择内容模板！");
                      return false;
                  }
                  if(!this.taskForm.checkType || this.taskForm.checkType ==''){
                      this.msgError("请选择任务类型！");
                      return false;
                  }
              }
              if(this.taskTypeFlag == 3){
                  if(!this.taskForm.checkType || this.taskForm.checkType ==''){
                      this.msgError("请选择任务类型！");
                      return false;
                  }
              }
          }
          //当为科员时，将本人的userId放入到list中，作为检查人员id
          if(this.userPost == "section_member"){
              if(!this.taskForm.taskType && this.taskForm.taskType != 0 ){
                  this.msgError("请选择任务类型！");
                  return false;
              }
              this.staffForm.deptAllCompanyList.forEach(detail => {
                  detail.userId = this.memberUserId;
              })
          }
          if((this.userPost == "section_chief"|| this.userPost =="section_member") && (this.taskTypeFlag == 2|| this.taskTypeFlag == 3) && this.staffForm.deptAllCompanyList.length == 0){
              this.msgError("请至少选择一个任务对象！");
              return false;
          }
          if(this.userPost != "section_member" && this.taskForm.checkType != 2 &&!this.validateStaffTaskNum()){
              this.msgError("请检查选择的任务对象是否全部分配完成");
              return false;
          }
          if(this.userPost == "section_chief" && !this.validateCheck()){
              return false;
          }
          return true;
      },
      //提交前校验勾选的人员是否匹配了所有的科长选择的场站
      validateStaffTaskNum(){
          var countNum = 0;
          this.staffForm.deptAllCompanyList.forEach(detail => {
              if(this.peopleIds.indexOf(detail.userId) >=0){
                  countNum++;
              }
          })
          if(countNum != this.staffForm.deptAllCompanyList.length){
              return false;
          }else{
              return true;
          }
      },
      async validateCheck(){
          await getValidateCheckResult(this.taskForm).then(response => {
              this.validateCheckResult = response.data;
              if(this.validateCheckResult == 'N'){
                  this.msgError("当前企业数量无法满足该随机模板，请检查！")
                  return false;
              }
              if(this.validateCheckResult == 'NULL'){
                  this.msgError("当前任务不存在，请检查是否还存在该任务！")
                  return false;
              }
          });
          return true;
      },
      /** 新增任务提交按钮 */
      submitTaskForm: function () {
          if(!this.validateBeforeTaskSubmit()){
              return;
          }
          this.taskForm.postCode = this.userPost;
          this.taskForm.peopleId = this.peopleIds;
          this.taskForm.deptAllCompanyList = this.staffForm.deptAllCompanyList;
          this.$refs["taskForm"].validate(valid => {
              if (valid) {
                  if (this.taskForm.id != undefined) {
                      updateInformation(this.taskForm).then(response => {
                          if (response.code === 200) {
                              this.msgSuccess("修改成功");
                              this.taskOpen = false;
                              this.getList();
                          }
                      });
                  } else {
                      addInformation(this.taskForm).then(response => {
                          if (response.code === 200) {
                              this.msgSuccess("新增成功");
                              this.taskOpen = false;
                              this.getList();
                              this.$router.push('/task/board')
                          }
                      });
                  }
              }
          });
      },
      /** 查询主任务信息列表 */
      getTaskList() {
          this.taskLoading = true;
          listInformation(this.queryParams).then(response => {
              this.informationList = response.rows;
              this.total = response.total;
              this.taskLoading = false;
          });
      },
      // 取消按钮
      cancelTask() {
          this.taskOpen = false;
          if (this.$refs != undefined && this.$refs.multiplePeopleTable != undefined) {
              this.$refs.multiplePeopleTable.clearSelection();
          }
          this.resetTask();
      },
      async assignStation(row) {
          if(this.staffForm.deptAllCompanyList.length == 0){
              this.msgError("请先选择任务对象");
              return ;
          }
          this.staffForm.open = true;
          this.staffForm.title = "分配场站";
          this.staffForm.staffUserId = row.userId;
          this.$nextTick(() => {
              if (this.staffForm.deptAllCompanyList.length != 0) {
                  this.staffForm.deptAllCompanyList.forEach(detail => {
                      if (detail.userId) {
                          this.$refs.multipleTable.toggleRowSelection(detail, true);
                      }
                  })
              }
          });
          this.staffForm.deptShowedCompanyList = this.staffForm.deptAllCompanyList;
      },
      //特定任务初始化时，需要获取已选择企业的长度，所以要重复查询一次数据库
      async getSpecialCompanyList(){
          if(this.userPost !='director' ){
              this.resetQueryCompanyParam();
              if(this.createByOwnFlag == "N"){
                  await getCompanyList(this.queryCompanyParams).then(response => {
                      this.specialTaskForm.list = response.data;
                      this.specialTaskForm.list = this.specialTaskForm.list.filter(detail =>this.checkedCompanyIds.indexOf(detail.stationId.toString()) >=0);
                      this.staffForm.deptAllCompanyList = this.specialTaskForm.list;
                  });
              }else{
                  await getCompanyList(this.queryCompanyParams).then(response => {
                      this.specialTaskForm.list = response.data;
                  });
              }
          }
      },
      //特定任务选择对象 单独写一个dialog
      async chooseSpecialObject(){
          this.resetQueryCompanyParam();
          if(this.createByOwnFlag == "N"){
              this.specialTaskForm.open = true;
              this.specialTaskForm.title = "选择检查对象";
              this.specialTaskForm.loading = false;
          }else{
              this.specialTaskForm.open = true;
              this.specialTaskForm.title = "选择检查对象";
              this.specialTaskForm.loading = false;
          }
          this.$nextTick(() => {
              if (this.checkedCompanyIds.length != 0) {
                  this.specialTaskForm.list.forEach(company => {
                      //因为split出来的数组是字符类型
                      if (this.checkedCompanyIds.indexOf(company.stationId) >= 0 || this.checkedCompanyIds.indexOf(company.stationId.toString()) >= 0) {
                          this.$refs.multipleCompanyTable.toggleRowSelection(company, true);
                      }
                  })
              }
          });
          //当点击人员的选择分配场站时，去数据库查询详情表，看对应的userId和stationId的对象list，只需要查一次，因为下面的勾选是根据userId来的
          if(this.staffForm.deptCheckedList.length == 0 && this.userPost !='director'){
              this.selectcheckedCompanyFromDB();
          }
      },
      async selectcheckedCompanyFromDB(){
          if(this.taskForm.id != undefined && this.taskForm.id !=null){
              await getCheckedCompanyListFromDB(this.taskForm.id).then(response => {
                  this.staffForm.deptCheckedList = response.data;
              });
          }
          if(this.staffForm.deptCheckedList.length !=0){
              this.staffForm.deptCheckedList.forEach(checked=>{
                  this.staffForm.deptAllCompanyList.forEach(detail=>{
                      if(checked.stationId == detail.stationId){
                          detail.userId = checked.userId;
                      }
                  })
              })
          }
          this.staffForm.deptShowedCompanyList =this.staffForm.deptAllCompanyList;
      },
      /*end*/

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有任务转发记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRecord(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
  .forwardUpload{
    display: flex;
  }
  .forwardUpload .el-upload-list--picture-card{
    height:75px;
  }
  .forwardUpload .el-upload-list--picture-card .el-upload-list__item{
    width:75px!important;
    height:75px!important;
  }
  .forwardUpload .el-upload--picture-card{
    width:75px!important;
    height:75px!important;
    line-height:75px!important;
  }
  .forwardUpload .el-upload-list__item{
    transition: none!important;
  }
  .forwardUpload .el-table .cell div{
    display: flex;
    justify-content: center;
    align-items:center;
  }
  .forwardUpload .el-upload--picture-card .el-icon-plus {
    display: flex;
    margin-top: 33%;
    justify-content: center;
  }
  .teding-dialog{
    .el-dialog__body{
      max-height:500px!important;
      overflow: auto;
    }
  }
 </style>
